home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / libray / libtext / wood.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  72 lines

  1. /*
  2.  * wood.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb, Robert F. Skinner
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: wood.c,v 4.0 91/07/17 14:44:35 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    wood.c,v $
  19.  * Revision 4.0  91/07/17  14:44:35  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "wood.h"
  25.  
  26. Wood *
  27. WoodCreate()
  28. {
  29.     return (Wood *)NULL;    /* No data associated with wood texture */
  30. }
  31.  
  32. /*ARGSUSED*/
  33. void
  34. WoodApply(wood, prim, ray, pos, norm, gnorm, surf)
  35. Wood *wood;
  36. Geom *prim;
  37. Ray *ray;
  38. Vector *pos, *norm, *gnorm;
  39. Surface *surf;
  40. {
  41.     Float red, grn, blu;
  42.     Float chaos, brownLayer, greenLayer;
  43.     Float perturb, brownPerturb, greenPerturb, grnPerturb;
  44.     Float t;
  45.  
  46.     chaos = Chaos(pos, 7);
  47.     t = sin(sin(8.*chaos + 7*pos->x +3.*pos->y));
  48.  
  49.     greenLayer = brownLayer = fabs(t);
  50.  
  51.     perturb = sin(40.*chaos + 50.*pos->z);
  52.     perturb = fabs(perturb);
  53.  
  54.     brownPerturb = .6*perturb + 0.3;
  55.     greenPerturb = .2*perturb + 0.8;
  56.     grnPerturb = .15*perturb + 0.85;
  57.     grn = 0.5 * pow(fabs(brownLayer), 0.3);
  58.     brownLayer = pow(0.5 * (brownLayer+1.0), 0.6) * brownPerturb;
  59.     greenLayer = pow(0.5 * (greenLayer+1.0), 0.6) * greenPerturb;
  60.  
  61.     red = (0.5*brownLayer + 0.35*greenLayer)*2.*grn;
  62.     blu = (0.25*brownLayer + 0.35*greenLayer)*2.0*grn;
  63.     grn *= max(brownLayer, greenLayer) * grnPerturb;
  64.  
  65.     surf->diff.r *= red;
  66.     surf->diff.g *= grn;
  67.     surf->diff.b *= blu;
  68.     surf->amb.r *= red;
  69.     surf->amb.g *= grn;
  70.     surf->amb.b *= blu;
  71. }
  72.